package 代码coding题OR模拟题;

public class leetcode917仅仅反转字母 {
	
	public static void main(String []args) {
		String s =  "a-bC-dEf-ghIj";
		System.out.println(process(s));
	}
	public static String  process(String s) {
		if(s.length() == 0 || s==null) {
			return null;
		}
		char []str = s.toCharArray();
		for(int i=0,j=str.length-1; i < j ;) {
			if(judge(str[i]) && judge(str[j])) {
				swap(str,i++,j--);
				continue;
			}
			if(!judge(str[i])) {
				i++;
			}
			if(!judge(str[j])) {
				j--;
			}
			
		}
		return new String(str);
	}
	public static boolean judge(char ch) {
		if(('a'<=ch && ch<='z') ||(ch<='Z' && ch>='A')) {
			return true;
		}
		return false;
	}
	public static void swap(char []s,int i,int j) {
		char temp = s[i];
		s[i] = s[j];
		s[j] = temp;
	}
}
